<div class="col-md-9 col-sm-7 col-12 right">


    <div class="box hidden">
        <div class="nickname"></div>
        <div class="del">
            <img src="/public/chat/img/bg.png" alt="" onclick="dellist(this)">
        </div>
        <div class="contents">
            <div class="boxs" id="chat_data">
                <!-- <div class="message"><span>阿斯頓阿薩阿薩</span></div> -->
            </div>
        </div>
        <div class="textarea">
            <div class="tools">
                <ul>
                    <li>
                        <a href="javascript:;" onclick="swTools('emojiBox')"><img src="__PUBLIC__/chat/img/xl.png" alt=""></a>
                    </li>
                </ul>
                {include file="/common/emoji" /}
            </div>
            <form action="" id="formdata">
                <textarea name="" id="textarea_data"></textarea>
                <span>按回车发送消息，ctrl+回车 换行</span>
                <input type="button" id="submit" value="发送(S)" onclick="onSubmit()">
            </form>
        </div>
    </div>
    <div class="box2 hidden">
        <div class="message hidden">
            <div class="title">新朋友</div>
            <div class="contents">
                <ul class="list-group mt-3">
                    <li class="list-group-item hidden" id="li_">
                        <span class="head">A</span>
                        <span class="badge btn-info btn" onclick="adds(this)" data-id='0' data-step="0">添加</span>
                        <div>nickname</div>
                        <div>13000000000</div>
                        <textarea name="" id="" class="form-control hidden" placeholder="请输入添加理由"></textarea>
                    </li>
                </ul>
            </div>
        </div>
    </div>
</div>
<script>
    function swTools(name) {
        $('#' + name).toggleClass('hidden');
    }

    // 提交对话
    function onSubmit() {
        var active = $('.home .center .list li.active a');
        var room_id = $(active).data('id');
        var user_id = "{:getSessInfo('id')}";

        var ide = "{:getSessInfo('ide')}";
        var input = $('#textarea_data').val();
        if ($(active).data('group') == 1) {
            var group_name = $(active).find('.nick').text();
            var groupide = $(active).find('.head').text();
            var data = {
                type: 'say',
                to_client_id: 'all',
                ide,
                room_id,
                user_id,
                group_name,
                groupide,
                content: input.replace('\r\n', '<br/>'),
            }
            console.log(data);

            ws.send(JSON.stringify(data))
        } else {
            //私聊
            var other_id = $(active).data('other_id');

            if (!input || input.replace(/\s/g, "") == '' || input.replace('\r\n', "") == '') {
                layer.msg('不可提交空数据');
                return false;
            }
            var data = {
                type: 'say_client',
                room_id,
                user_id,
                other_id,
                ide,
                content: input.replace('\r\n', '<br/>')
            }
            ws.send(JSON.stringify(data))
        }

        document.title = '首页';
        $('#textarea_data').val("").focus();
    }


    //回车
    $(document).keypress(function(e) {
        if (e.keyCode == 10 && e.ctrlKey) {
            var text = $('#textarea_data').val();
            text = text + '\n';
            $('#textarea_data').val(text);
        } else if (e.keyCode == 13) {
            onSubmit();
            return false;
        }
    })

    function other_adds(e) {
        var id = $(e).data('id');
        $.get("{:url('confirm_friend')}?id=" + id, function(res) {
            layer.msg(res.msg)
            if (res.code == 1) {
                var data = {
                    type: 'get_friend',
                    other_id: res.data
                };
                console.log(JSON.stringify(data));
                ws.send(JSON.stringify(data));
            }
        })
    }
</script>